/*****************************************************************************
Copyright 2006 Kervin L. Pierre
    EMAIL: otlkcon@adevsoft.com

This file is part of Otlkcon.

Otlkcon is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

Otlkcon is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Lesser GNU General Public License for more details.

You should have received a copy of the Lesser GNU General Public License
along with Otlkcon; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*******************************************************************************/

#pragma once
#include "StdAfx.h"
#include "O_IProp.h"
#include "O_IMessage.h"
#include "O_ITable.h"

class O_IContainer;

class O_IContainerAdviseSink : public IMAPIAdviseSink
{
public:
    MAPI_IUNKNOWN_METHODS(IMPL);
    MAPI_IMAPIADVISESINK_METHODS(IMPL);

    O_IContainerAdviseSink( O_IContainer *con );
    ~O_IContainerAdviseSink();

    HRESULT UpdateContentsTableRow( O_ENTRYID *msgEid, int flags );
	HRESULT UpdateHierarchyTableRow( O_ENTRYID *folderEid, int flags );
    HRESULT UpdateRemoteMessage(O_IMessage *msg, ULONG flags);

    O_IContainer *container;

    ULONG cRef;
};

bool operator <(const O_ENTRYID u1, const O_ENTRYID u2);

class O_IContainer : public O_IProp
{
public:
	//MAPI_IUNKNOWN_METHODS(IMPL);
    MAPI_IMAPICONTAINER_METHODS(IMPL);

    O_IContainer(void);
    ~O_IContainer(void);

    void Destroy();
    HRESULT Create( otlkcon_generic_msgstore *mstr, MAPIUID ig, MAPIUID tg );
    HRESULT Load( otlkcon_generic_msgstore *mstr, O_ENTRYID *eid );

    HRESULT ProcessEvent( otlkcon_event_struct *ev );
    HRESULT OnGetIdRes( otlkcon_event_struct *ev );
	HRESULT OnUploadRes( otlkcon_event_struct *ev );
    STDMETHODIMP UpdateRemoteMessage(O_IMessage *msg, ULONG flags);
    HRESULT DeleteRemoteMessage(O_IMessage *msg, int flags);
    HRESULT ProcessRemoteMessagesPending(ULONG ulFlags);
    HRESULT GetXPP();

    O_ITable *hierarchyTable;
    O_ITable *contentsTable;
    O_ITable *assocContentsTable;

    //! EntryID for account backend.
    O_ENTRYID *xpAccountEID;

	typedef set<O_ENTRYID> UploadSet;
	UploadSet	messageToUpload;

    BOOL isForeignView;

    ULONG objectCreateConnection;

    LPMAPIADVISESINK adviseSink;
};

